package orz.mikeneck.server.locrec.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public final class DateUtils {

	public static String DAFULT_TIME_FORMAT = "yyyy/M/d-kk:mm";

	public static Date parseDate(String date, String timeZone) throws ParseException {
		String zone = getTimeZone(timeZone);
		return parseDate(date, TimeZone.getTimeZone(zone));
	}

	public static Date parseDate(String date, TimeZone zone) throws ParseException {
		SimpleDateFormat format = getSimpleDateFormat(zone);
		return format.parse(date);
	}

	public static String getTimeZone(String timeZone) {
		return (timeZone == null)? "UTC" : timeZone;
	}

	public static SimpleDateFormat getSimpleDateFormat(String timeZone) {
		TimeZone zone = TimeZone.getTimeZone(getTimeZone(timeZone));
		return getSimpleDateFormat(zone);
	}

	public static SimpleDateFormat getSimpleDateFormat(TimeZone zone) {
		SimpleDateFormat format = getSimpleDateFormat();
		format.setTimeZone(zone);
		return format;
	}

	public static SimpleDateFormat getSimpleDateFormat() {
		return new SimpleDateFormat(DAFULT_TIME_FORMAT);
	}

	public static String formatDate(Date date) throws ParseException {
		return getSimpleDateFormat().format(date);
	}

	public static String formatDate(Date date, String timeZone) throws ParseException {
		return getSimpleDateFormat(timeZone).format(date);
	}

	public static String formatDate(Date date, TimeZone timeZone) throws ParseException {
		return getSimpleDateFormat(timeZone).format(date);
	}
	
}
